package com.hlkj.baojin.controller;

import com.hlkj.baojin.entity.EarlyAlarmRecord;
import com.hlkj.baojin.entity.dto.*;
import com.hlkj.baojin.service.AlarmRecordService;
import com.hlkj.baojin.utils.bean.JsonResult;
import com.hlkj.baojin.utils.bean.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 徐其伟
 * @Description:
 * @date 18-12-17 上午10:23
 */
@Api(value = "/bjjk", description = "权限管理")
@RequestMapping("/bjjk")
@RestController
public class AlarmRecordController {
    @Autowired
    private AlarmRecordService alarmRecordService;


    @ApiOperation(value = "报警列表", tags = {"报警记录"})
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = AlarmRecordDto.class)})
    @PostMapping(value = "/alarm/list/{page}/{size}")
    public ResponseEntity<?> alarmList(@RequestBody AlarmSearch alarmSearch, @PathVariable Integer page, @PathVariable Integer size) {
        return ResponseEntity.ok(JsonResult.success(alarmRecordService.listAlarmRecord(alarmSearch, new Page(page, size))));
    }
    @ApiOperation(value = "预警列表", tags = {"报警记录"})
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = EarlyAlarmRecordDto.class)})
    @PostMapping(value = "/earlyAlarm/list/{page}/{size}")
    public ResponseEntity<?> earlyAlarmList(@RequestBody AlarmSearch alarmSearch, @PathVariable Integer page, @PathVariable Integer size) {
        return ResponseEntity.ok(JsonResult.success(alarmRecordService.listEarlyAlarmRecord(alarmSearch, new Page(page, size))));
    }
    @ApiOperation(value = "报警上报", tags = {"报警记录"})
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = JsonResult.class)})
    @PostMapping(value = "/alarm/{id}/commit")
    public ResponseEntity<?> commitAlarm(@RequestBody AlarmReason alarmReason, @PathVariable String id) {
        alarmRecordService.commitAlarm(id, alarmReason);
        return ResponseEntity.ok(JsonResult.success());
    }
    @ApiOperation(value = "报警结果上报", tags = {"报警记录"})
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = JsonResult.class)})
    @PostMapping(value = "/alarm/{id}/handle/commit")
        public ResponseEntity<?> commitHandle(@RequestBody HandleMethod handleMethod, @PathVariable String id) {
        alarmRecordService.commitHandle(id, handleMethod);
        return ResponseEntity.ok(JsonResult.success());
    }
    @ApiOperation(value = "报警波形图", tags = {"报警记录"})
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = StatusDataVO.class)})
    @GetMapping(value = "/alarm/{id}/wave")
    public ResponseEntity<?> alarmWaveMsg(@PathVariable String id) {
        return ResponseEntity.ok(JsonResult.success(alarmRecordService.alarmWaveMsg(id)));
    }
    @ApiOperation(value = "报警详情", tags = {"报警记录"})
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = AlarmRecordDto.class)})
    @GetMapping(value = "/alarm/{id}/info")
    public ResponseEntity<?> alarmInfo(@PathVariable String id) {
        return ResponseEntity.ok(JsonResult.success(alarmRecordService.getAlarmRecord(id)));
    }
    @ApiOperation(value = "预警详情", tags = {"报警记录"})
    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = EarlyAlarmRecordDto.class)})
    @GetMapping(value = "/earlyAlarm/{id}/info")
    public ResponseEntity<?> earlyAlarmInfo(@PathVariable String id) {
        return ResponseEntity.ok(JsonResult.success(alarmRecordService.getEarlyAlarm(id)));
    }
}
